<template>
    <div class="screen-adapter" id="screenAdapter" :style="style">
      <slot />
    </div>
  </template>
  
  <script setup>
  import { onMounted, reactive } from "vue";
  import { debounce } from "./utils";
  const props = defineProps({
    width: {
      type: String,
      default: "1920",
    },
    height: {
      type: String,
      default: "1080",
    },
  });
  const style = reactive({
    width: props.width + "px",
    height: props.height + "px",
    transform: "scale(1) ",
    overflow: 'hidden'
  });
  
  // 获取放大缩小比例
  const getScale = () => {
    const w = window.innerWidth / props.width;
    const h = window.innerHeight / props.height;
    return [w, h];
    // return w < h ? w : h;
  };
  // 设置比例
  const setScale = () => {
    style.transform = "scale(" + getScale()[0] + "," + getScale()[1] + ") ";
    // style.transform = "scale(" + getScale() + ") translate(-50%, -50%)";
    console.log("任你千变万化,我都不会影响性能");
  };
  onMounted(() => {
    setScale();
    window.onresize = debounce(setScale, 1000);
    // window.onresize = Debounce(setScale, 1000);
  });
  </script>
  
  <style lang="less" scoped>
  .screen-adapter {
    transform-origin: 0 0;
    // position: absolute;
    // left: 50%;
    // top: 50%;
    transition: 0.3s;
    // background: red;
  }
  </style>
  